package com.edu.web.controller.info;

import com.edu.framework.websocket.service.CanteenService;
import com.edu.system.domain.TNotice;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.edu.common.annotation.Log;
import com.edu.common.core.controller.BaseController;
import com.edu.common.core.domain.AjaxResult;
import com.edu.common.enums.BusinessType;
import com.edu.system.domain.TCanteen;
import com.edu.system.service.ITCanteenService;
import com.edu.common.utils.poi.ExcelUtil;
import com.edu.common.core.page.TableDataInfo;

/**
 * 餐厅Controller
 *
 * @author xxxx
 * @date 2023-12-21
 */
@RestController
@RequestMapping("/system/canteen")
public class TCanteenController extends BaseController
{
    @Autowired
    private ITCanteenService tCanteenService;
    @Resource
    private CanteenService wsCanteenService;

    /**
     * 查询餐厅列表
     */
    @PreAuthorize("@ss.hasPermi('system:canteen:list')")
    @GetMapping("/list")
    public TableDataInfo list(TCanteen tCanteen)
    {
        startPage();
        List<TCanteen> list = tCanteenService.selectTCanteenList(tCanteen);
        return getDataTable(list);
    }

    /**
     * 启用/禁用
     */
    @PreAuthorize("@ss.hasPermi('system:canteen:onOff')")
    @GetMapping(value = "/onOff/{id}/{status}")
    public AjaxResult onOff(@PathVariable("id") Long id, @PathVariable("status") Integer status)
    {
        TCanteen t = new TCanteen();
        t.setId(id);
        t.setStatus(status);
        return success(tCanteenService.updateTCanteen(t));
    }

    /**
     * 导出餐厅列表
     */
    @PreAuthorize("@ss.hasPermi('system:canteen:export')")
    @Log(title = "餐厅", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TCanteen tCanteen)
    {
        List<TCanteen> list = tCanteenService.selectTCanteenList(tCanteen);
        ExcelUtil<TCanteen> util = new ExcelUtil<TCanteen>(TCanteen.class);
        util.exportExcel(response, list, "餐厅数据");
    }

    /**
     * 获取餐厅详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:canteen:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tCanteenService.selectTCanteenById(id));
    }

    /**
     * 新增餐厅
     */
    @PreAuthorize("@ss.hasPermi('system:canteen:add')")
    @Log(title = "餐厅", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TCanteen tCanteen)
    {
        return toAjax(tCanteenService.insertTCanteen(tCanteen));
    }

    /**
     * 修改餐厅
     */
    @PreAuthorize("@ss.hasPermi('system:canteen:edit')")
    @Log(title = "餐厅", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TCanteen tCanteen)
    {
        int i = tCanteenService.updateTCanteen(tCanteen);
        wsCanteenService.pushMsg(new ArrayList<>());
        return toAjax(i);
    }

    /**
     * 删除餐厅
     */
    @PreAuthorize("@ss.hasPermi('system:canteen:remove')")
    @Log(title = "餐厅", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tCanteenService.deleteTCanteenByIds(ids));
    }
}
